{#include file="top.php"#}
<script type="text/javascript">
    function sidebar_newreport(uid,page){
        $.getJSON("/block.php?action=b16_1",{uid:uid,page:page},function(data){
           $('#sidebar_person_newreport').html(data.report);
        });
    }
    function ajax_share_report_ponits(id,action_name,remark){
        $.ajax({
            url : '/ajax_points.php?action=ajax_fb_points',
            type : 'POST',
            data: "id="+id+"&code={#php#}echo md5('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].'imoreHK');{#/php#}&action_name="+action_name+"&remark="+remark,
            dataType : 'json',
            success: function(data){
                if(data.ret==0){
                   // console.info("未登入");
                }else if(data.ret==1){
                    if(data.data.ret==1){
                       // console.info(data.data.action);
                    }else{
                      //  console.info(data.data.reason);
                    }

                }else{
                   // console.info(data.reason);
                }
            }
        });

        var fb_count = 0;
        fb_count = parseInt($('#fb_count_'+id).html())+1;
        $('#fb_count_'+id).html(fb_count);

    }
    function showpop(text){
        $("#fullbg").fadeIn();
        $("#dialog1").fadeOut('slow');
        $("#dialog").fadeOut('slow');
        showLB('#dialog_popup',0);
        $("#popupText").text(text);
    }
    function closeLB(){
        $("#fullbg").fadeOut('slow');
        $("#dialog").fadeOut('slow');
        $("#dialog1").fadeOut('slow');
        $("#dialog_popup").fadeOut('slow');
    }
    function plikes(sec,sid){
        $.getJSON("/product.php?action=ajax&t=3",{sec:sec,sid:sid},function(data){
            if(parseInt(data.recode)==1){
                $('#'+sec+'_likes_'+sid).html(data.likes);
            }else if(parseInt(data.recode)==2){
                $("#loginText").text("以iMORE帳戶登入");
                $("#login").attr("onClick","login('plikes(\\'"+sec+"\\',"+sid+")')");
                $("#login_type").attr("onClick","fnblogin('plikes(\\'"+sec+"\\',"+sid+")')");
                showLB('#dialog',0);
            }else{
                showpop(data.msg);
            }
        });
    }


/*     function fb_recommend(sec,sid){
        $.getJSON("/product.php?action=ajax&t=12",{sec:sec,sid:sid},function(data){
            if(parseInt(data.recode)==1){
                $('#fb_recommend').html(data.likes);
            }else if(parseInt(data.recode)==2){
                $("#loginText").text("以iMORE帳戶登入");
                $("#login").attr("onClick","login('fb_recommend(\\'"+sec+"\\',"+sid+")')");
                $("#login_type").attr("onClick","fnblogin('fb_recommend(\\'"+sec+"\\',"+sid+")')");
                showLB('#dialog',0);
            }else{
                showpop(data.msg);
            }
        });
    } */


    function login(func){

        var email = $('#email').val();
        if($.trim(email).length==0){
            showpop("{#$NO_USERNAME#}");
            $('#email').focus();
            return false;
        }
        var password = $('#password').val();
        if($.trim(password).length==0){
            showpop("{#$NO_PASSWORD#}");
            $('#password').focus();
            return false;
        }
        /*
                var captcha = $('#captcha').val();
                if($.trim(captcha).length==0){
                        showpop("{#$ERR_CAPTCHA#}");
                        $('#captcha').focus();
                        return false;
                }
         */

        $.getJSON("/member.php?action=ajax_login_imore",{email:email,password:password/*,captcha:captcha*/},function(data){
            if(parseInt(data.ret)==1){
                showpop(data.msg);
            }else if(parseInt(data.ret)==2){
                showpop(data.msg);
                $('#captcha').attr("src","captcha.php?t="+Math.random());
            }else{closeLB();memberBar();eval(func);}
        });
    }

    function login_fnb(func){
        var email = $('#email').val();
        if($.trim(email).length==0){
            showpop("{#$NO_USERNAME#}");
            $('#email').focus();
            return false;
        }
        var password = $('#password').val();
        if($.trim(password).length==0){
            showpop("{#$NO_PASSWORD#}");
            $('#password').focus();
            return false;
        }
        /*
                var captcha = $('#captcha').val();
                if($.trim(captcha).length==0){
                        showpop("{#$ERR_CAPTCHA#}");
                        $('#captcha').focus();
                        return false;
                }
         */


        $.getJSON("/member.php?action=ajax_login_fnb",{email:email,password:password/*,captcha:captcha*/},function(data){
            if(parseInt(data.ret)==1){
                showpop(data.msg);
            }else if(parseInt(data.ret)==2){
                showpop(data.msg);
                $('#captcha').attr("src","captcha.php?t="+Math.random());
            }else{closeLB();memberBar();eval(func);}
        });
    }

    function fnblogin(func){
        $("#loginText").text("F&amp;B 會員登入 REGISTRATION");
        $("#login").attr("onClick","login_fnb("+func+")");
        $("#login_type_text").text("以 iMORE 登入");
        $("#login_type").attr("onClick","itriallogin("+func+")");
        $("#loginTextName").css("background-position","0 -940px");
        $("#classlogo").attr("class","itrial ir");

    }
    function itriallogin(func){
        $("#loginText").text("iTRIAL 會員登入 REGISTRATION");
        $("#login").attr("onClick","login("+func+")");
        $("#login_type_text").text("以 F&B 登入");
        $("#login_type").attr("onClick","fnblogin("+func+")");
        $("#loginTextName").css("background-position","0 -900px");
        $("#classlogo").attr("class","fabtn ir");

    }

    function showLB(ct,n){
        var sh=$(document).height();
        var sw=$(document).width();
        var st=$(window).scrollTop();
        var ch=$(window).height();
        var cw=$(window).width();
        var tbT=(Number(ch)/3+Number(st))+"px";
        var tbL=(Number(cw)/2)+"px";
        if(n==0){
            $("#fullbg").css({width:sw,height:sh});
            $(ct).css({top:tbT,left:tbL});
            $("#fullbg").fadeTo('slow', 0.4);
            $(ct).fadeIn('slow');
            $(window).scroll(function(){showLB(ct,1)});
            $(window).resize(function(){showLB(ct,1)});
        }else{
            if($("#fullbg").css("display")=="block"){
                $("#fullbg").css({width:sw,height:sh});
                $(ct).css({top:tbT,left:tbL});
            }
        }
    }
    function user_like(uid){
        $.getJSON("/person.php?action=ajax&t=1",{uid:uid},function(data){
            if(parseInt(data.recode)==2){
                $('#like_bt').html("<a href='javascript:void(0);' class='btn_grey' onclick='user_unlike("+uid+")'>取消關注</a>");
                $('#user_likes').text(parseInt($('#user_likes').text()) + 1);
            }else if(parseInt(data.recode)==1){
                $("#loginText").text("以iMORE帳戶登入");
                $("#login").attr("onClick","login('user_like("+uid+")')");
                $("#login_type").attr("onClick","fnblogin('user_like("+uid+")')");
                showLB('#dialog',0);
            }else{
                showpop(data.msg);
            }
        });
    }
    function user_unlike(uid){
        $.getJSON("/person.php?action=ajax&t=2",{uid:uid},function(data){
            if(parseInt(data.recode)==2){
                var l = parseInt($('#user_likes').html());
                $('#user_likes').html(l-1);
                $('#like_bt').html("<a  href='javascript:void(0);' class='btn_pink' onclick='user_like("+uid+")'>關注</a>");
            }else if(parseInt(data.recode)==1){
                $("#loginText").text("以iMORE帳戶登入");
                $("#login").attr("onClick","login('user_unlike("+uid+")')");
                $("#login_type").attr("onClick","fnblogin('user_unlike("+uid+")')");
                showLB('#dialog',0);
            }else{
                showpop(data.msg);
            }
        });
    }
</script>


<div class="body">
    <div class="main">
        <div class="u_box_top">
            <figure class="img_box">
                <img src="{#$user.photo_l#}" width=77 />
            </figure>
            <strong class="name">{#$user.username#}</strong>
            <span class="btn_bk"><span id='user_likes'>{#$user.likes#}</span> Fans</span>
            {#if $uid neq $mid#}
            <span id='like_bt'>
                {#if $user.islike==0#}
                <a href="javascript:void(0);" class="btn_pink" onclick='user_like({#$user.id#})'>關注</a>
                {#else#}
                <a  href="javascript:void(0);" class="btn_grey" onclick='user_unlike({#$user.id#})'>取消關注</a>
                {#/if#}
            </span>
            {#/if#}
            <p>年齡 / {#$user.age#}</p>
            <p>臉部膚質 / {#$user.body_skin#}</p>
            <p>iTrial 分 / {#$user.points#}<a href="{#optimize_url('help', 'show','page=4')#}" target="_blank"><i class="icon point"></i></a></p>
        </div>
        <div class="tab_b_box tab_b_box_r">
                <a href="{#optimize_url('person', 'report','username='|cat:$user.username)#}">產品報告</a>
                <a href="{#optimize_url('person', 'attention','ps=3&username='|cat:$user.username)#}">關注會員</a>
                <a href="{#optimize_url('person', 'recommen','username='|cat:$user.username)#}" class="curr">推介報告</a>
            <em class="line"></em>
        </div>
        {#foreach  from=$user_like_reports item=v key=k#}
        <div class="b_box b_box_pro_rep {#if $k eq 3#}b_box_pro_rep_1{#/if#}">
            <div class="bd">
                <div class="box_hd box_hd_w">
                    <figure class="img_box">
						<p class="img_p"><a href="{#optimize_url('product', 'detail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id)#}"><span><img src="{#$v.product.photo#}"></span></a></p>
                    </figure>
                    <h2 class="title_en"><a href="{#optimize_url('product', 'detail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id)#}" class="product_brand">{#$v.product.type_name#}</a></h2>
                    <h3 class="title_cn"><a href="{#optimize_url('product', 'detail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id)#}">{#$v.product.cname#}</a></h3>
                    <div class="intro">
                        <span><sup>好</sup>{#$v.product.good#}</span>
                        <em>/</em>
                        <span><sup>一般</sup>{#$v.product.common#}</span>
                        <em>/</em>
                        <span><sup>差</sup>{#$v.product.bad#}</span>
                    </div>
                </div>
                <div class="box_mid">
                    <p>總評：{#if $v.report.well==1#}很好{#else if $v.report.well==2#}好{#else if $v.report.well==3#}一般{#else if $v.report.well==4#}差{#else if $v.report.well==5#}很差{#/if#}</p>
                    <div class="star_box">
                        <table>
                            <tbody><tr>
                                    {#foreach  from=$v.report.category item=v1 key=k1#}
                                    <th>{#$v1.name#}</th>
                                    <td><strong class="star star_{#$v1.value#}">{#$v1.value#}星</strong></td>
                                    {#if (($k1+1)%3) eq 0#}</tr><tr>{#/if#}
                                    {#/foreach#}
                                </tr>
                            </tbody></table>
                        <div class="btn_box_r">
                            <a href="javascript:void(0);" onclick="plikes('report',{#$v.report.id#})" class="btn_pink">推介</a>
                             <!--<a href="http://www.facebook.com/sharer.php?u={#$thisUrl#}&t={#$v.report.title#}-{#$v.product.cname#}" class="btn_fb_share" target=_blank>facebook share</a>-->

                            <span><a id='report_likes_{#$v.report.id#}'>{#$v.report.likes#}</a>個推介</span>
                             <div class="facebook_share">
                                <div class="count"><span class="count_button_nub">
                                    </span> <div  id="fb_count_{#$v.report.id#}">{#$v.report.fb_count#}</div></div>
                                <script>
                                    function postToFeed{#$v.report.id#}(id) {
                                        // calling the API ...
                                        var obj = {
                                            method: 'feed',
                                            link: '{#php#}echo DOMAIN;{#/php#}{#substr($v.report.share_url,1)#}',
                                            picture: '{#php#}echo DOMAIN;{#/php#}{#$v.product._photo_url#}',
                                            name: '{#str_replace("'","’",$v.report.title)#}',
                                            caption: '{#str_replace("'","’",$v.product.cname)#}',
											description: '{#str_replace("'","’",str_replace(array("\r\n", "\n", "\r"),"",strip_tags(htmlspecialchars_decode($v.report.body))))#}'
                                        };
                                        FB.ui(obj, function(response){
                                            if(response['post_id']){
                                                var remark = "{#str_replace("'","’",$v.report.title)#}"
                                                ajax_share_report_ponits(id,"share_report",remark);
                                            }
                                        });
                                    }</script>
                                <a class="btn_fb_share"
                                   title="Share on Facebook"
                                   onclick="postToFeed{#$v.report.id#}({#$v.report.id#});" href="javascript:void(0);"></a>


                            </div>
                        </div>
                    </div>
                <p class="que"><a class="que" href="{#optimize_url('product', 'reportDetail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id|cat:'&rid='|cat:$v.report.id)#}">{#$v.report.title#}</a></p>
                </div>
                <div class="box_bot">
                    <p><a href="{#optimize_url('product', 'reportDetail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id|cat:'&rid='|cat:$v.report.id)#}">{#$v.report.body#}</a></p>
                    <ul class="clearfix">
                        {#foreach  from=$v.report.content item=v2 key=k2#}
                        {#if $v2.p && $k2<4#}
                        <li {#if $k2 eq 3#}class="last"{#/if#}>
							<div class="img_box"><p class="img_p"><a href="{#optimize_url('product', 'reportDetail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id|cat:'&rid='|cat:$v.report.id)#}"><span><img src="{#$v2.p#}"></span></a></p></div>
                        </li>{#/if#}
                        {#/foreach#}
                    </ul>
                    <a class="more" href="{#optimize_url('product', 'reportDetail','mtype='|cat:$v.product.member_type|cat:'&pid='|cat:$v.product.id|cat:'&rid='|cat:$v.report.id)#}">更多</a>
                </div>

            </div>
        </div>
        {#/foreach#}
        {#$pagelist#}
    </div>
    <!-- main-->
    <div class="sidebar">

        {#show_block('b2',1,'','sidebar_ad')#}
        {#show_block('b1',2,'','sidebar_function')#}
        {#show_block('b3',0,'','sidebar_search')#}
        {#show_block('b16',0,'','sidebar_newreport','&uid='|cat:$user.id)#}
        {#show_block('b13',0,'','sidebar_registation')#}
        {#show_block('b9',0,'','sidebar_tutorial b_box')#}
        {#show_block('b6',0,'','sidebar_facebook')#}
    </div>
    <!-- sidebar -->

</div><!--body-->
<!--  遮罩層  -->
<div id="fullbg" ></div>
<div  class="irpopbox popbox b_box" id="dialog" style="z-index: 60;	display:none;">
    <div class="hd">
        <h2 class="ir ht" id=loginTextName><span id=loginText>iTRIAL 會員登入 REGISTRATION</span></h2>
        <a class="popclose" style="cursor:pointer" onclick="closeLB();">close</a>
    </div>
    <div class="bd">
        <div class="lbox">
            <p>會員名稱 USERNAME</p>
            <input type="text" class="ipt" name="email" id="email">
            <p>密碼 PASSWORD</p>
            <input type="password" class="ipt" name="password" id="password">
            <a class="btn_s btn_s_login" onclick="login()" style="cursor:pointer" id="login"><strong>login</strong></a>
            <ul>
                <li><a href="/member.php?action=forgetPassword">忘記密碼</a></li>
                <li><a href="/member.php?action=reg&toURL={#$thisUrl#}">註冊新帳號</a></li>
            </ul>
        </div>
        <div class="rbox">
            <div class="lgbox"><em class="hack"></em>
                <a class="fbtn ir" href="/member.php?action=login_facebook&toURL={#$thisUrl#}"><strong>以facebook登入</strong></a><span><a class="fb_link" href="/member.php?action=login_facebook&toURL={#$thisUrl#}">以facebook登入</a></span>
            </div>
            <div class="lgbox lgbox2" onClick="fnblogin()" id=login_type style="cursor:pointer" ><em class="hack"></em>
                <a class="fabtn ir" id=classlogo><strong>以F&amp;B登入</strong></a><span id=login_type_text  >以F&amp;B登入</span>
            </div>
        </div>
    </div>
</div>
<div style="top:400px;z-index:60;display:none;" class="apopbox popbox b_box" id="dialog_popup">
    <div class="hd">
        <h2 class="ir ht"><span>提示信息 ALERT</span></h2>
        <a class="popclose" onclick="closeLB();" style="cursor:pointer">close</a>            </div>
    <div class="bd">
        <p id="popupText"></p>
        <a class="btn_b btn_s_im_back" href="javascript:void(0);" onclick="closeLB();"><strong>立即返回</strong></a>            </div>
</div>
{#include file="footer.php"#}